/**
 * @file usr_lte.c
 * @author zcj (605607217@qq.com)
 * @brief
 * @version ecu-中控
 * @date 2023-11-06
 *
 * @copyright Copyright (c) 2023
 *
 */

#include "luat_network_adapter.h"
#include "luat_mobile.h"
#include "main.h"

/**
 * @brief Set the 4g ccid object
 *
 * @param lte
 * @param index
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
void set_4g_ccid(DEV_LTE_T *lte, uint8_t index)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	luat_mobile_get_iccid(index, lte->ccid, sizeof(lte->ccid));
	//usr_log("lte->ccid = %s", lte->ccid);
	luat_rtos_mutex_unlock(lte->mutex);
}

/**
 * @brief Get the 4g ccid object
 *
 * @param lte
 * @return char*
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
char *get_4g_ccid(DEV_LTE_T *lte)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	char *ccid = lte->ccid;
	luat_rtos_mutex_unlock(lte->mutex);
	return ccid;
}

/**
 * @brief Set the 4g imsi object
 *
 * @param lte
 * @param index
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
void set_4g_imsi(DEV_LTE_T *lte, uint8_t index)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	luat_mobile_get_imsi(index, lte->imsi, sizeof(lte->imsi));
	luat_rtos_mutex_unlock(lte->mutex);
}

/**
 * @brief Get the 4g imsi object
 *
 * @param lte
 * @return char*
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
char *get_4g_imsi(DEV_LTE_T *lte)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	char *imsi = lte->imsi;
	luat_rtos_mutex_unlock(lte->mutex);
	return imsi;
}

/**
 * @brief Set the 4g imei object
 *
 * @param lte
 * @param index
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
void set_4g_imei(DEV_LTE_T *lte, uint8_t index)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	luat_mobile_get_imei(index, lte->imei, sizeof(lte->imei));
	luat_rtos_mutex_unlock(lte->mutex);
}

/**
 * @brief Get the 4g imei object
 *
 * @param lte
 * @return char*
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
char *get_4g_imei(DEV_LTE_T *lte)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	char *imei = lte->imei;
	luat_rtos_mutex_unlock(lte->mutex);
	return imei;
}

/**
 * @brief Set the 4g sim status object
 *
 * @param lte
 * @param state
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
void set_4g_sim_status(DEV_LTE_T *lte, SIM_STATE_M state)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	lte->sim_status = state;
	luat_rtos_mutex_unlock(lte->mutex);
}

SIM_STATE_M get_4g_sim_status(DEV_LTE_T *lte)
{
	SIM_STATE_M state;
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	state = lte->sim_status;
	luat_rtos_mutex_unlock(lte->mutex);
	return state;
}
int16_t get_bsloc_rssi(DEV_BSLOC_T *bsloc)
{
	int16_t rssi;
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	rssi=bsloc->rssi;
	luat_rtos_mutex_unlock(bsloc->mutex);
	return rssi;
}
int16_t get_bsloc_rsrq(DEV_BSLOC_T *bsloc)
{
	int16_t rsrq;
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	rsrq=bsloc->rsrq;
	luat_rtos_mutex_unlock(bsloc->mutex);
	return rsrq;
}
uint16_t get_bsloc_mcc(DEV_BSLOC_T *bsloc)
{
	uint16_t mcc;
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	mcc=bsloc->mcc;
	luat_rtos_mutex_unlock(bsloc->mutex);
	return mcc;
}
uint16_t get_bsloc_mnc(DEV_BSLOC_T *bsloc)
{
	uint16_t mnc;
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	mnc=bsloc->mnc;
	luat_rtos_mutex_unlock(bsloc->mutex);
	return mnc;
}
uint16_t get_bsloc_lac(DEV_BSLOC_T *bsloc)
{
	uint16_t lac;
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	lac=bsloc->lac;
	luat_rtos_mutex_unlock(bsloc->mutex);
	return lac;
}
uint32_t get_bsloc_cid(DEV_BSLOC_T *bsloc)
{
	uint32_t cid;
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	cid=bsloc->cid;
	luat_rtos_mutex_unlock(bsloc->mutex);
	return cid;
}
void set_bsloc_rssi(DEV_BSLOC_T *bsloc,int16_t rssi)
{

	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	bsloc->rssi=rssi;
	luat_rtos_mutex_unlock(bsloc->mutex);
}
void set_bsloc_rsrq(DEV_BSLOC_T *bsloc,int16_t rsrq)
{
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	bsloc->rsrq=rsrq;
	luat_rtos_mutex_unlock(bsloc->mutex);
}
void set_bsloc_mcc(DEV_BSLOC_T *bsloc,uint16_t mcc)
{
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	bsloc->mcc=mcc;
	luat_rtos_mutex_unlock(bsloc->mutex);
}
void set_bsloc_mnc(DEV_BSLOC_T *bsloc,uint16_t mnc)
{
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	bsloc->mnc=mnc;
	luat_rtos_mutex_unlock(bsloc->mutex);
}
void set_bsloc_lac(DEV_BSLOC_T *bsloc,uint16_t lac)
{
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	bsloc->lac=lac;
	luat_rtos_mutex_unlock(bsloc->mutex);
}
void set_bsloc_cid(DEV_BSLOC_T *bsloc,uint32_t cid)
{
	luat_rtos_mutex_lock(bsloc->mutex, LUAT_WAIT_FOREVER);
	bsloc->cid=cid;
	luat_rtos_mutex_unlock(bsloc->mutex);
}
/**
 * @brief Set the 4g net status object
 *
 * @param lte
 * @param state
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
void set_4g_net_status(DEV_LTE_T *lte, NET_STATE_M state)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	lte->net_status = state;
	luat_rtos_mutex_unlock(lte->mutex);
}

/**
 * @brief Get the 4g net status object
 *
 * @param lte
 * @return NET_STATE_M
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
NET_STATE_M get_4g_net_status(DEV_LTE_T *lte)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	NET_STATE_M state = lte->net_status;
	luat_rtos_mutex_unlock(lte->mutex);
	return state;
}

/**
 * @brief Get the 4g csq object
 *
 * @param lte
 * @return uint8_t
 * @author zcj (605607217@qq.com)
 * @date 2023-11-06
 */
uint8_t get_4g_csq(DEV_LTE_T *lte)
{
	luat_rtos_mutex_lock(lte->mutex, LUAT_WAIT_FOREVER);
	uint8_t csq = lte->csq;
	luat_rtos_mutex_unlock(lte->mutex);
	return csq;
}

